#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=100000, inf=0x7ffffff;

int main() {
#ifdef DEBUG
  freopen("2.in", "r", stdin);
  freopen("2.out", "w", stdout);
#endif

  static int stone[maxn+1];
  int n, m;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d", stone+i);
  }

  scanf("%d", &m);
  for (int i=1; i<=m; i++) {
    int a, b, r, sum=0, ans=inf;
    scanf("%d %d %d", &r, &a, &b);
    if (stone[r]==0) {
      printf("-1\n");
      continue;
    }
    if (r==b) {
      printf("%d\n", stone[r]);
      stone[r]=0;
      continue;
    }
    for (int j=r-1; j>=a; j--) {
      sum = sum^stone[j];
      if (j<=b && sum<ans) {
	ans = sum;
      }
    }
    if (ans<stone[r]) {
      printf("%d\n", stone[r]-ans);
      stone[r]=ans;
    } else {
      printf("-1\n");
    }
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
